/**
 * Created by 13576 on 2018/1/25.
 */
import React from 'react';
import {Collapse, Timeline, Spin, Row, Col} from 'antd';
import {messages} from 'share/common'

class ApproveHistoryWorkFlow extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      historyData: [],
    };
  }

  getHistory() {
    const historyData = this.props.infoData;
    let children = [];
    historyData.map((item, i) => {
      children.push(
        this.getHistoryRender(item, i)
      )
    });
    return children;
  }

  getColor(value) {
    let model = {};
    switch (value.operationType) {
      case 1000:
        if (value.operation === 1001) {
          model.color = "cyan";
          model.text = messages('common.create')/*新建*/;
        } else if (value.operation === 1002) {
          model.color = "blue";
          model.text = messages('common.submit')/*提交*/;
          model.dot = "up-circle-o";
        } else if (value.operation === 1003) {
          model.color = "red";
          model.text = messages('common.withdraw')/*撤回*/;
          model.dot = "down-circle-o";
        } else if (value.operation === 1004) {
          model.color = "green";
          model.text = messages('pay.key139')/*审批通过*/;
          model.dot = "check-circle-o";
        } else if (value.operation === 1005) {
          model.color = "red";
          model.text = messages('pay.key140')/*审批驳回*/;
          model.dot = "close-circle-o";
        } else if (value.operation === 6001) {
          model.color = "yellow";
          model.text = messages('pay.key141')/*暂挂中*/;
        } else if (value.operation === 6002) {
          model.color = "red";
          model.text = messages('pay.key142')/*已取消*/;
        } else if (value.operation === 6003) {
          model.color = "green";
          model.text = messages('pay.key143')/*已完成*/;
        } else if (value.operation === 6004) {
          model.color = "green";
          model.text = messages('pay.key144')/*取消暂挂*/;
        } else if (value.operation === 9001) {
          model.color = "blue";
          model.text = messages('pay.key2')/*支付*/;
          model.dot = "pay-circle-o";
        } else if (value.operation === 9002) {
          model.color = "blue";
          model.text = messages('pay.key3')/*退款*/;
          model.dot = "down-circle-o";
        } else if (value.operation === 9003) {
          model.color = "blue";
          model.text = messages('pay.key28')/*退票*/;
          model.dot = "down-circle-o";
        } else if (value.operation === 9004) {
          model.color = "blue";
          model.text = messages('pay.key4')/*反冲*/;
          model.dot = "clock-circle-o";
        } else {
          model.color = "grey";
          model.text = messages('pay.key145')/*未知*/;
        }
        break;
      case 1001:
        if (value.operation === 1001) {
          model.color = "blue";
          model.text = messages('common.submit')/*提交*/;
          model.dot = "up-circle-o";
        } else if (value.operation === 1002) {
          model.color = "red";
          model.text = messages('common.withdraw')/*撤回*/;
          model.dot = "down-circle-o";
        } else if (value.operation === 5004) {
          model.color = "blue";
          model.text = messages('pay.key146')/*还款提交*/;
          model.dot = "up-circle-o";
        } else if (value.operation === 2001) {
          model.color = "green";
          model.text = messages('pay.key139')/*审批通过*/;
          model.dot = "check-circle-o";
        } else if (value.operation === 5009) {
          model.color = "grey";
          model.text = messages('pay.key147')/*添加会签*/;
          model.dot = "check-circle-o";
        }
        break;
      case 1002:
        if (value.operation === 2001) {
          model.color = "green";
          model.text = messages('pay.key139')/*审批通过*/;
          model.dot = "check-circle-o";
        } else if (value.operation === 2002) {
          model.color = "red";
          model.text = messages('pay.key140')/*审批驳回*/;
          model.dot = "close-circle-o";
        } else if (value.operation === 5009) {
          model.color = "grey";
          model.text = messages('pay.key147')/*添加会签*/;
          model.dot = "check-circle-o";
        }
        break;
      case 1003:
        if (value.operation === 3001) {
          model.color = "green";
          model.text = messages('pay.key148')/*审核通过*/;
          model.dot = "check-circle-o";
        } else if (value.operation === 4001) {
          model.color = "grey";
          model.text = messages('pay.key149')/*财务付款*/;
        } else if (value.operation === 3002) {
          model.color = "red";
          model.text = messages('pay.key150')/*审核驳回*/;
          model.dot = "close-circle-o";
        } else if (value.operation === 4001) {
          model.color = "grey";
          model.text = messages('pay.key149')/*财务付款*/;
        } else if (value.operation === 4000) {
          model.color = "grey";
          model.text = messages('pay.key151')/*财务付款中*/;
        } else if (value.operation === 7001) {
          model.color = "grey";
          model.text = messages('pay.key152')/*核定金额修改*/;
        } else if (value.operation === 7002) {
          model.color = "grey";
          model.text = messages('pay.key153')/*核定汇率修改*/;
        } else if (value.operation === 7003) {
          model.color = "grey";
          model.text = messages('pay.key154')/*核定金额和汇率修改*/;
        } else if (value.operation === 5009) {
          model.color = "grey";
          model.text = messages('pay.key147')/*添加会签*/;
          model.dot = "close-circle-o";
        }
        break;
      case 1004:
        if (value.operation === 4011) {
          model.color = "green";
          model.text = messages('pay.key155')/*开票通过*/;
          model.dot = "check-circle-o";
        } else if (value.operation === 4002) {
          model.color = "red";
          model.text = messages('pay.key156')/*开票驳回*/;
        } else if (value.operation === 3002) {
          model.color = "grey";
          model.text = messages('pay.key147')/*添加会签*/;
        }
        break;
    }
    return model;
  }

  getHistoryRender(item, i) {
    if (item) {
      let model = this.getColor(item);
      return (
        <Timeline.Item color={model.color} key={i}>
          <Row>
            <Col span={3}>
              <div style={{fontWeight: 'bold'}}>{model.text}</div>
            </Col>
            <Col span={4}>
              <div style={{color: "rgba(0,0,0,0.5)"}}>{item.lastModifiedDate}</div>
            </Col>
            <Col span={5}>
              <div style={{}}> {item.employeeName}-{item.employeeID} </div>
            </Col>
            <Col>
              <div>{item.operationDetail}</div>
            </Col>
          </Row>
        </Timeline.Item>)
    }
    return ''
  }

  render() {
    return (
      <Spin spinning={this.props.loading}>
        <div className="approve-history">
          <div className="collapse">
            <Collapse bordered={false} defaultActiveKey={['1']}>
              <Collapse.Panel header={messages('pay.key157')/*审批历史*/} key="1">
                <div style={{paddingTop: 10, paddingLeft: 15}}>
                  {this.props.infoData.length ? (<Timeline>
                    {this.getHistory()}
                  </Timeline>) : (<div style={{textAlign: "center"}}>{messages('pay.key158')/*暂无数据*/}</div>)}
                </div>
              </Collapse.Panel>
            </Collapse>
          </div>
        </div>
      </Spin>
    )
  }
}

ApproveHistoryWorkFlow.propTypes = {
  infoData: React.PropTypes.array.isRequired,  //传入的基础信息值
  loading: React.PropTypes.bool                //是否显示正在加载中图标
};

ApproveHistoryWorkFlow.defaultProps = {
  infoData: [],
  loading: false
};

export default ApproveHistoryWorkFlow


